package com.example.administrator.newsdemo;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;

/**
 * Created by Administrator on 2018/5/7 0007.
 */

public class TitleFragmentAdapter extends FragmentPagerAdapter {
    private List<Fragment> fragments = null;
    private String[] titles;
    public TitleFragmentAdapter(FragmentManager fm,List<Fragment> fragments,String[] titles) {
        super(fm);
        this.fragments = fragments;
        this.titles = titles;
    }


    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if(titles !=null && titles.length>0){
            return titles[position];
        }
        return null;
    }
}
